package com.tyut.controller;

import com.tyut.musicdreamer.framework.starter.convention.result.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 健康检查控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/health")
@RequiredArgsConstructor
public class HealthController implements HealthIndicator {

    /**
     * 健康状态检查
     *
     * @return 健康状态
     */
    @Override
    public Health health() {
        return Health.up()
                .withDetail("service", "search")
                .withDetail("status", "UP")
                .build();
    }

    /**
     * 健康检查接口
     *
     * @return 健康检查结果
     */
    @GetMapping
    public Result<Map<String, Object>> check() {
        log.info("健康检查");
        Map<String, Object> health = new HashMap<>();
        health.put("service", "musicdreamer-service-search");
        health.put("status", "UP");
        health.put("timestamp", System.currentTimeMillis());
        return Result.success(health);
    }

    /**
     * 获取服务信息
     *
     * @return 服务信息
     */
    @GetMapping("/info")
    public Result<Map<String, Object>> info() {
        log.info("获取服务信息");
        Map<String, Object> info = new HashMap<>();
        info.put("service", "musicdreamer-service-search");
        info.put("version", "1.0.0");
        info.put("description", "MusicDreamer搜索服务");
        info.put("timestamp", System.currentTimeMillis());
        return Result.success(info);
    }
} 